package lu.med.praxiswahl.wahlumed.client.zytologie;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.border.Border;
import javax.swing.table.TableCellRenderer;

import lu.med.praxiswahl.wahlumed.client.wclient.Main;

/**
 * 
 * @author Lars Holger Roth
 */
public class ZytologieCellRenderer implements TableCellRenderer {
	private Color black = new Color(0, 0, 190);
	private Color white = new Color(255, 255, 255);
	private Color red = new Color(235, 0, 0);
	private Color grey = new Color(255, 255, 255);
	private Color darkGrey = new Color(200, 200, 200);
	private Color yellow = new Color(205, 105, 0);
	private Font bold = new Font("Arial", Font.BOLD, 12);
	private Color blue = new Color(0, 0, 250);
	private ZytologieTableModel model;
	private Main dataManager;
	private String str;
	private Font extraFond = new Font("Arial", Font.PLAIN, 16);

	public ZytologieCellRenderer(ZytologieTableModel model) {
		this.model = model;
		
	}

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		JLabel label = new JLabel();

		label.setOpaque(true);
		Border b = BorderFactory.createEmptyBorder(1, 1, 1, 1);
		label.setBorder(b);
		label.setFont(table.getFont());
		label.setForeground(table.getForeground());
		label.setBackground(table.getBackground());

		/*
		 * if(column == 2) { label.setFont(extraFond ); }
		 */
		// Sonderf�lle f�r die Farben
		// Jedes Datum wird Rot eingefärbt
		if (column == 1) {
			str = (String) model.getValueAt(row, column);
			if (!str.equals("     \"")) {
				label.setForeground(red);
				label.setBackground(white);
				label.setFont(bold);
			}
			
		}

		if (column == 4) {
			str = (String) model.getValueAt(row, column);
			if (str.equals("Trier")) {
				label.setForeground(yellow);
				label.setFont(bold);
			}
		}

		if (model.isFourth(row)) {
			// Zeile grau hinterlegen
			label.setBackground(darkGrey);
		}

		if (model.isSpecial(row)) {
			if (column == 6) {
				// label.setBackground(red);
				label.setForeground(red);
				label.setFont(bold);
			}
		}

		if (model == null) {
			label.setText("");
		} else {
			if (column == 0)
				label.setText("" + model.getValueAt(row, column));
			else
				label.setText((String) model.getValueAt(row, column));
		}

		if (hasFocus) {
			label.setBackground(black);
			label.setForeground(white);
		} else {
			// Angezeigte Spalte in Modellspalte umwandeln
			column = table.convertColumnIndexToModel(column);
		}

		if (isSelected) {
			label.setBackground(blue);
			label.setForeground(white);
			label.setFont(bold);
		}

		return label;
	}
}